package com.limao.Tool;

import java.io.IOException;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;

import com.limao.CacheManager.BaseDataCacheManager;

/**
 * 短信通平台
 * @author Administrator
 *
 */
public class SMSDuanXT {
	/**网站 http://www.dxton.com/ **/
	private static String BASEurl = "http://sms.106jiekou.com/gbk/sms.aspx";
	//private static String BASEurl = "http://106xin.com/gbk/sms.aspx";    
	
	private static String account = "lank498";
	private static String password = "19890911";//   19890911  4817153
	private static String sitename = "狸猫商城";

	public static boolean send(String mobile,String code)
	{
		boolean success=false;
		
		String url=BaseDataCacheManager.getInstance().Load_Param("SMSDuanXTUrl");
		if(CacheClass.isEmpty(url))
		{
			url=BASEurl;
		}
		
		HttpClient client = new HttpClient(); 
		PostMethod method = new PostMethod(url); 
		client.getParams().setContentCharset("UTF-8");
		method.setRequestHeader("ContentType","application/x-www-form-urlencoded;charset=UTF-8");

		try {
			String content = java.net.URLEncoder.encode("您的验证码是：【"+code+"】。如需帮助请联系客服。", "gb2312");
			NameValuePair[] data = {
				    new NameValuePair("account", account), 
				    new NameValuePair("password", password), //密码可以使用明文密码或使用32位MD5加密
				    //new NameValuePair("password", StringUtil.MD5Encode(password)),
				    new NameValuePair("mobile", mobile), 
				    new NameValuePair("content", content),
			};
			
			method.setRequestBody(data);
			client.executeMethod(method);	
			
			String result =method.getResponseBodyAsString();
						
			if("100".equals(result)){
				success = true;
				System.out.println(result);
			}else{
				success = false;
				System.out.println("短信通发送失败 code:"+result);
			}
			
		} catch (HttpException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		return success;
	}
}
